#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    map<int, int> mp1, mp2;
    for(int i = 0; i < n; i++) cin >> a[i], mp1[a[i]]++;
    for(int i = 0; i < n; i++) cin >> b[i], mp2[b[i]]++;
    if(mp1.size() + mp2.size() >= 4) {
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
}

signed main() {
    int t;
    cin >> t;
    while(t--) solve();
}